package com.jzo2o.foundations.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.domain.Serve;
import com.jzo2o.foundations.model.dto.request.*;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.model.dto.response.ServeTypeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author DarkClown
 * @date 2024-08-15 20:28
 * @project_name jzo2o-foundations-01-0
 * @parem
 **/
@Validated
@RestController("operationServeController")
@RequestMapping("/operation/serve")
@Api(tags = "服务端 - 区域管理相关接口")
public class ServeController {
    @Autowired
    private IServeService serveService;

    @GetMapping("/page")
    @ApiOperation("服务类型分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO) {
        return serveService.page(servePageQueryReqDTO);
    }

    @PostMapping("/batch")
    @ApiOperation("添加服务")
    public void add(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOList){
        serveService.bachAdd(serveUpsertReqDTOList);
    }

    @PutMapping("/{id}")
    @ApiOperation("区域服务价格修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务Id", required = true,dataTypeClass = Long.class),
            @ApiImplicitParam(name = "price", value = "价格", required = true,dataTypeClass = BigDecimal.class)
    })
    public void update(@PathVariable("id") Long id, @RequestParam("price")BigDecimal price) {
        serveService.update(id,price);
    }

    @PutMapping("/onSale/{id}")
    @ApiOperation("区域服务上架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务Id", required = true,dataTypeClass = Long.class)
    })
    public Serve onSale(@PathVariable("id") Long id) {
        return serveService.onSale(id);
    }


    @PutMapping("/offSale/{id}")
    @ApiOperation("区域服务下架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务Id", required = true,dataTypeClass = Long.class)
    })
    public Serve offSale(@PathVariable("id") Long id) {
        return serveService.offSale(id);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("区域服务删除功能")
    public Serve delete(@PathVariable("id") Long id) {
        return serveService.delete(id);
    }

    @PutMapping("/onHot/{id}")
    @ApiOperation("区域服务设置热门功能")
    public Serve onHot(@PathVariable("id") Long id) {
        return serveService.onHot(id);
    }

    @PutMapping("/offHot/{id}")
    @ApiOperation("区域服务取消热门功能")
    public Serve offHot(@PathVariable("id") Long id) {
        return serveService.offHot(id);
    }
}
